if(typeof(JS_WP_ESTORE_VARIATION_ADD_STRING) == 'undefined')
{
	JS_WP_ESTORE_VARIATION_ADD_STRING = "+";
}
if(typeof(JS_WP_ESTORE_CURRENCY_SYMBOL) == 'undefined')
{
	JS_WP_ESTORE_CURRENCY_SYMBOL = "$";
}
if(typeof(JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR) == 'undefined')
{
	JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR = ",";
}
variation_add_string = JS_WP_ESTORE_VARIATION_ADD_STRING;//"+";
currency_symbol = JS_WP_ESTORE_CURRENCY_SYMBOL;//"$";
thousands_sep = JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR;//",";
split_char = "[" + variation_add_string;

function CheckTok (object1)
{	
    var var_add_amt,ary=new Array ();     // where we parse
    ary = val.split ("[");          // break apart
    variation_price_val = ary[1];	
    if(variation_price_val != null)
    {	    	
    	//remove the addition,currency and ] symbol then trim it
    	var_add_amt = variation_price_val.replace(variation_add_string, "");
    	var_add_amt = var_add_amt.replace(currency_symbol, "");
    	var_add_amt = var_add_amt.replace("]", "");
    	var_add_amt = var_add_amt.replace(thousands_sep, "");
    	var_add_amt = trim(var_add_amt);
    	if(eStoreIsNumeric(var_add_amt)){
    		amt = amt + var_add_amt*1.0;
    	}
    	else{
    		alert("Error! Variation addition amounts are not numeric. Please contact the admin and mention this error.");
    	}
    }
}
function ReadForm1 (object1, buttonType) 
{
    // Read the user form
    var i,j,pos;
    amt=0;val_total="";val_combo="";		
	val_1st_half="";
	variation_name="";
			
    for (i=0; i<object1.length; i++) 
    {     
        // run entire form
        obj = object1.elements[i];           // a form element

        if (obj.type == "select-one") 
        {   // just selects
            if (obj.name == "quantity" ||
                obj.name == "amount") continue;
	        pos = obj.selectedIndex;        // which option selected
	        val = obj.options[pos].value;   // selected value		        
            variation_name = val.split (split_char);          // break apart
            val_combo = val_combo + " (" + trim(variation_name[0]) + ")";
	        CheckTok(object1);
        }
        if (obj.type == "text")
        {   // just text
        	if (obj.name == "add_qty") continue;
	        val = obj.value;   // selected value
	        if (val.length != 0)
	        {
	        	val_combo = val_combo + " (" + val + ")";
	        }
        }
    }

	// Now summarize everything we have processed above
	val_total = object1.product_name_tmp1.value + val_combo;
	if(buttonType == 1)
	{
		object1.product.value = val_total;				
		object1.price.value = parseFloat(object1.price_tmp1.value) + amt;					
	}
	else if(buttonType == 2)
	{
		object1.item_name.value = val_total;		
		if (object1.custom_price){
			var custom_price = parseFloat(object1.custom_price.value);
			var min_amt = parseFloat(object1.price_tmp1.value);
			if(custom_price<min_amt)
			{
				alert("The minimum price you can specify is "+ min_amt);
				return false;
			}
			else{
				object1.amount.value = custom_price + amt;
			}
		}
		else{			
			object1.amount.value = parseFloat(object1.price_tmp1.value) + amt;
		}		
		setCookie("cart_in_use","true",1);			
	}
	else if(buttonType == 3)
	{
		object1.item_name.value = val_total;				
		object1.a3.value = parseFloat(object1.price_tmp1.value) + amt;	
	}		
}	
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function eStoreIsNumeric(input)
{
    return (input - 0) == input && input.length > 0;
}	